package safari.model.message;

import java.sql.SQLException;
import java.util.List;

import safari.model.common.ListVO;
import safari.model.common.PagingBean;

public class MessageServiceImpl implements MessageService {
	private PagingBean pb1,pb2;
	private MessageDao dao;
	public MessageServiceImpl(MessageDao dao){
		this.dao=dao;
	}
	
	@Override
	public int newMessage(MessageVO msgvo) throws SQLException {
		return dao.newMessage(msgvo);
	}

	@Override
	public ListVO getReceivedMessageList(IdAndPageVO ipvo)
			throws SQLException {
		int pageNo=1;
		if(ipvo.getPage()!=0){
			pageNo=ipvo.getPage();
		}
		List<MessageVO> receivedList=dao.getReceivedMessageList(ipvo);
		//total contents가 몇개인지 넣어서 pagingBean 만들었어요
		//System.out.println("여기 messageDao 받은메세지 몇개니?:"+dao.getNumberOfReceivedMessage(ipvo.getId()));
		pb1=new PagingBean(dao.getNumberOfReceivedMessage(ipvo.getId()),pageNo);
		return new ListVO(receivedList,pb1);
		
	}

	@Override
	public ListVO getSendedMessageList(IdAndPageVO ipvo)
			throws SQLException {
		int pageNo=1;
		if(ipvo.getPage()!=0){
			pageNo=ipvo.getPage();
		}
		List<MessageVO> sendedList=dao.getSendedMessageList(ipvo);
		
		System.out.println("몇개?"+dao.getNumberOfSendedMessage(ipvo.getId()));
		//total contents가 몇개인지 넣어서 pagingBean 만들었어요
		pb2=new PagingBean(dao.getNumberOfSendedMessage(ipvo.getId()),pageNo);
		System.out.println("총페이지수:"+pb2.getTotalPage());
		System.out.println("총페이지그룹수:"+pb2.getTotalPageGroup());
		
		return new ListVO(sendedList,pb2);
	}

	@Override
	public MessageVO viewOneMessage(int no) throws SQLException {
		// TODO Auto-generated method stub
		return dao.viewOneMessage(no);
	}

	@Override
	public int deleteMessage(int no) throws SQLException {
		// TODO Auto-generated method stub
		return dao.deleteMessage(no);
	}

}
